package club.mzywucai.blog.air_portal.pojo.domain;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Random;

/**
 * @author mzywucai
 * @Description 创建文件码，以及验证部分
 * @date 2019/5/24
 */
@Component
public class CreateNewFileCode {

    @Autowired
    FileCodeContainer container;

    /**
     * @Description 获取文件码
     * @author mzywucai
     * @time 2019-05-24
     * @see 
     * @return   java.lang.String
     * @params  []
     */
    public String getFileCode() {
        String code = createFileCode();

        while (container.hasContainCode(code)) {
            code = createFileCode();
        }

        container.addCode(code);

        return code;
    }

    private String createFileCode() {
        Long speed = System.currentTimeMillis();
        Random rand = new Random(speed);

        String code = "";
        for(int a = 0; a < 6; a++){
            code += rand.nextInt(10);
        }

        return code;
    }
}
